<template>

<div id="authInfo">
  <el-row id="homeBar">
    <mu-appbar title="审核信息" style="background-color:#409EFF">
      <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'AuthMenu' }"/>
    </mu-appbar>
  </el-row>
  <el-row>
    <el-col :span="12">
    </el-col>
    <el-col :span="12">
      <i class="el-icon-arrow-down" style="float:right" @click="handleTools"></i>
    </el-col>
  </el-row>
  <div class= "tools" v-show="tools">
    <el-row>
      <el-col :xs="6" :sm="4" :md="3" :lg="3">
        玩家ID
      </el-col>
      <el-col :xs="18" :sm="20" :md="21" :lg="21">
        <el-input v-model="condition.uid" size="mini" @blur="handleFind"></el-input>
      </el-col>
    </el-row>
      <!-- <el-col :xs="24" :sm="8" :md="8" :lg="8">
        <el-col :xs="6" :sm="6" :md="6" :lg="6">
          起始日期
        </el-col>
        <el-col :xs="18" :sm="18" :md="18" :lg="18">
          <el-date-picker
            v-model="condition.startDay"
            type="date"
            placeholder="选择起始日期"
            value-format="yyyy-MM-dd"
            @change="handleFind"
            size="mini">
          </el-date-picker>
        </el-col>
      </el-col>

      <el-col :xs="24" :sm="8" :md="8" :lg="8">
        <el-col :xs="6" :sm="6" :md="6" :lg="6">
          结束日期
        </el-col>
        <el-col :xs="18" :sm="18" :md="18" :lg="18">
          <el-date-picker
            v-model="condition.endDay"
            type="date"
            placeholder="选择结束日期"
            value-format="yyyy-MM-dd"
            @change="handleFind"
            size="mini">
          </el-date-picker>
        </el-col>
      </el-col> -->

  </div>

  <el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="uid"
        label="玩家ID">
      </el-table-column>
      <el-table-column
        prop="binderUid"
        label="上级ID">
      </el-table-column>
      <el-table-column
        prop="realName"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="wechat"
        label="微信号">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="手机号">
      </el-table-column>
      <el-table-column
        prop="subTime"
        label="申请时间">
      </el-table-column>

      <el-table-column label="同意"
      width="80px" v-if="this.agentLevel !== 1">

        <template slot-scope="scope">
          <el-row v-if="!isCarrieroperator">
            <el-button type="primary" icon="el-icon-check" size="mini"  @click='handleCheck(scope.row, 3)'></el-button>
          </el-row>
          <el-row v-if="isCarrieroperator">
            <el-row v-if="agentUid === scope.row.binderUid">
              <el-button type="primary" icon="el-icon-check" size="mini"  @click='handleCheck(scope.row, 3)'></el-button>
            </el-row>
            <el-row v-if="agentUid !== scope.row.binderUid">
              <span style="color:red;">非直属申请无法操作</span>
            </el-row>
          </el-row>
        </template>

      </el-table-column>

      <el-table-column label="拒绝"
      v-if="this.isAdmin || this.isGm1"
      width="80px">

        <template slot-scope="scope">
          <el-row>
            <el-button  type="primary" icon="el-icon-close" size="mini"  @click='handleCheck(scope.row, 2)'></el-button>
          </el-row>
        </template>

      </el-table-column>

      <el-table-column label="强制同意"
      v-if="this.isAdmin || this.isGm1"
      width="80px">
        <template slot-scope="scope">
          <el-row>
            <el-button type="primary"  size="mini"  @click='handleForce(scope.row, 3)' >强制</el-button>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
  </el-row>

  <el-row>
    <center>
      <el-pagination
        small
        layout="prev, pager, next"
        :total="condition.total"
        :page-size="condition.pageSize"
        :current-page="condition.currentPage"
        @current-change="handleCurrentChange">
      </el-pagination>
    </center>
  </el-row>
</div>

</template>

<style >
#authInfo  .el-row {
  margin-bottom: 16px;
}
#authInfo   .el-col {
  margin-bottom: 8px;
}
#authInfo .el-message-box {
  width: 200px !important;
}

.el-message-box {
  width: 200px !important;
}

</style>

<script>
  import moment from 'moment'
  export default {
    data () {
      return {
        tools: true,
        tableData: [],
        condition: {
          checkStatus: 1,
          uid: '',
          currentPage: 1,
          pageSize: 10,
          total: 0,
          account: sessionStorage.getItem('account')
        },
        isAdmin: false,
        isCarrieroperator: false,
        isGm1: false,
        agentUid: 0,
        agentLevel: 0
      }
    },
    methods: {
      handleTools () {
        if (this.tools) {
          this.tools = false
        } else {
          this.tools = true
        }
      },
      handleFind () {
        let that = this
        if (this.condition.uid === '' || this.condition.uid.length === 0) {
          this.condition.uid = -1
        }
        this.$axios({
          method: 'get',
          url: '/api/AgentService.getAgentApply',
          params: this.condition
        })
        .then(function (resp) {
          that.condition.uid = ''
          for (let item in resp.data.data) {
            resp.data.data[item].subTime = moment.utc(resp.data.data[item].subTime).zone(-8).format('YYYY-MM-DD HH:mm:ss')
          }
          that.tableData = resp.data.data
          that.condition.total = resp.data.page.total
        })
      },
      handleCheck (row, checkStatus) {
        this.$confirm('确定审核此信息？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let that = this
          this.$axios({
            method: 'get',
            url: '/api/AgentService.checkAgent',
            params: {'account': sessionStorage.getItem('account'), 'uid': row.uid, 'checkStatus': checkStatus, 'checkAgentLevel': row.checkAgentLevel}
          })
          .then(function (resp) {
            if (resp.data.status === 'success') {
              that.$message({
                showClose: true,
                message: '审核成功',
                type: 'success'
              })
              that.init()
            } else {
              that.$message({
                showClose: true,
                message: resp.data.cause,
                type: 'warning'
              })
            }
          })
          .catch(function (error) {
            console.log(error)
          })
        }).catch(() => {
          return false
        })
      },
      handleCurrentChange (val) {
        this.condition.currentPage = val
        this.handleFind()
      },
      handleForce (row, checkStatus) {
        this.$confirm('确定审核此信息？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let that = this
          this.$axios({
            method: 'get',
            url: '/api/AgentService.checkAgentForce',
            params: {'account': sessionStorage.getItem('account'), 'uid': row.uid, 'checkStatus': checkStatus, 'checkAgentLevel': row.checkAgentLevel}
          })
          .then(function (resp) {
            if (resp.data.status === 'success') {
              that.$message({
                showClose: true,
                message: '审核成功',
                type: 'success'
              })
              that.init()
            } else {
              that.$message({
                showClose: true,
                message: resp.data.cause,
                type: 'warning'
              })
            }
          })
        }).catch(() => {
          return false
        })
      },
      init () {
        this.handleFind()
      },
      getAgentUid () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/AuthService.getAgentUid'
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.agentUid = resp.data.data
            that.agentLevel = resp.data.agentLevel
          }
        })
      }
    },
    mounted () {
      if (sessionStorage.getItem('role') === 'admin') {
        this.isAdmin = true
      }
      if (sessionStorage.getItem('role') === 'carrieroperator') {
        this.isCarrieroperator = true
      }
      if (sessionStorage.getItem('role') === 'gm1') {
        this.isGm1 = true
      }
      this.getAgentUid()
      this.init()
    }
  }
</script>
